# datasets

dataset_type = 'VOCDataset'
data_root = 'data/VOCdevkit/'
img_norm_cfg = dict(mean=[123.675, 116.28, 103.53], std=[1, 1, 1], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFile', to_float32=True),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(type='PhotoMetricDistortion',
         brightness_delta=32,
         contrast_range=(0.5, 1.5),
         saturation_range=(0.5, 1.5),
         hue_delta=18),
    dict(type='Expand',
         mean=[123.675, 116.28, 103.53],
         to_rgb=True,
         ratio_range=(1, 4)),
    dict(type='MinIoURandomCrop',
         min_ious=(0.1, 0.3, 0.5, 0.7, 0.9),
         min_crop_size=0.3),
    dict(type='Resize', img_scale=(300, 300), keep_ratio=False),
    dict(type='Normalize',
         mean=[123.675, 116.28, 103.53],
         std=[1, 1, 1],
         to_rgb=True),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='MultiScaleFlipAug',
         img_scale=(300, 300),
         flip=False,
         transforms=[
             dict(type='Resize', keep_ratio=False),
             dict(type='Normalize',
                  mean=[123.675, 116.28, 103.53],
                  std=[1, 1, 1],
                  to_rgb=True),
             dict(type='ImageToTensor', keys=['img']),
             dict(type='Collect', keys=['img'])
         ])
]
data = dict(
    samples_per_gpu=64,
    workers_per_gpu=4,
    train=dict(
        type='RepeatDataset',
        times=1,
        dataset=dict(
            type='VOCDataset',
            ann_file=[
                'data/VOCdevkit/VOC2007/ImageSets/Main/trainval.txt',
                'data/VOCdevkit/VOC2012/ImageSets/Main/trainval.txt'
            ],
            img_prefix=['data/VOCdevkit/VOC2007/', 'data/VOCdevkit/VOC2012/'],
            pipeline=train_pipeline)),
    val=dict(type='VOCDataset',
             ann_file='data/VOCdevkit/VOC2007/ImageSets/Main/test.txt',
             img_prefix='data/VOCdevkit/VOC2007/',
             pipeline=test_pipeline),
    test=dict(type='VOCDataset',
              ann_file='data/VOCdevkit/VOC2007/ImageSets/Main/test.txt',
              img_prefix='data/VOCdevkit/VOC2007/',
              pipeline=test_pipeline))

# models

input_size = 300
model = dict(
    type='SSDLite',
    pretrained='',
    backbone=dict(
        type='MobileNetV2',
        width_mult=1.0,
        out_feature_names=['13', 'conv'],
        pretrained=
        '/content/drive/My Drive/models/ImageNet_PreTrained_Models/mobilenetv2_1.0-0c6065bc.pth'
    ),
    neck=dict(
        type='SSDLiteNeckMobileNetv2',
        in_channel=1280,
        extra_channels=[512, 256, 256, 64]),
    bbox_head=dict(
        type='SSDLiteHead',
        in_channels=(96, 1280, 512, 256, 256, 64),
        num_classes=20,
        anchor_generator=dict(
            type='SSDAnchorGenerator',
            scale_major=False,
            input_size=300,
            basesize_ratio_range=(0.2, 0.9),
            strides=[16, 30, 60, 100, 150, 300],
            ratios=[[2], [2, 3], [2, 3], [2, 3], [2], [2]]),
        bbox_coder=dict(
            type='DeltaXYWHBBoxCoder',
            target_means=[0.0, 0.0, 0.0, 0.0],
            target_stds=[0.1, 0.1, 0.2, 0.2])))
cudnn_benchmark = True
train_cfg = dict(
    assigner=dict(
        type='MaxIoUAssigner',
        pos_iou_thr=0.5,
        neg_iou_thr=0.5,
        min_pos_iou=0.0,
        ignore_iof_thr=-1,
        gt_max_assign_all=False),
    smoothl1_beta=1.0,
    allowed_border=-1,
    pos_weight=-1,
    neg_pos_ratio=3,
    debug=False)
test_cfg = dict(
    nms=dict(type='nms', iou_thr=0.45),
    min_bbox_size=0,
    score_thr=0.02,
    max_per_img=200)

# schedules

optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005)
optimizer_config = dict(grad_clip=None)
lr_config = dict(policy='CosineAnealing', min_lr=0, by_epoch=True, warmup=None)
total_epochs = 100

# default_runtime

evaluation = dict(interval=10, metric='mAP')
checkpoint_config = dict(interval=10, create_symlink=False)
log_config = dict(
    interval=50,
    hooks=[dict(type='TextLoggerHook'),
           dict(type='TensorboardLoggerHook')])
dist_params = dict(backend='nccl')
log_level = 'INFO'
load_from = None
resume_from = None
workflow = [('train', 1)]
work_dir = '/content/drive/My Drive/models/object_detect_benchmark/PascalVOC'
gpu_ids = range(0, 1)
